using System;

namespace EventBehaviorTree
{
    [Serializable]
    public class TaskNode : EventNode
    {
        private TaskPattern _pattern;
        private Action Action = delegate { };
        public TaskNode() { _pattern = TaskPattern.Normal; }
        public TaskNode(string pattern) { _pattern = (TaskPattern)Enum.Parse(typeof(TaskPattern), pattern); }
        public void SetNodeFunction(IAction IAction) { Action = IAction.Action; }
        public override void NodeEvent(NodeMessage nodeMessage)
        {
            if (nodeMessage != NodeMessage.COMMAND_Stop)//todo: coroutine for action
            {
                Action();
                switch (_pattern)
                {
                    case TaskPattern.Normal:
                        CompositeNodeEvent(NodeMessage.Success);
                        break;
                    case TaskPattern.Abort:
                        CompositeNodeEvent(NodeMessage.REQUEST_Abort);
                        break;
                    default:
                        break;
                }
            }
        }
    }
}
